/*
 * Copyright (c) 2024 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
 * easyAda is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#include <hal/interrupt_ctrl.h>
#include <plat/autoconf.h>
#ifdef CONFIG_DRIVERS_GIC_V3
#include <arch/gic_v3.h>
#else
#include <arch/gic_v2.h>
#endif


void interrupt_init_controller(void)
{
    gic_dist_init(DEVICE_VBASE_GICD);
}

void interrupt_init_local_controller(void)
{
#ifdef CONFIG_DRIVERS_GIC_V3
    gic_cpu_init(DEVICE_VBASE_GICR);
#else
    gic_cpu_init(DEVICE_VBASE_GICC);
#endif
}

void interrupt_sgi_trigger(uint32_t id, int32_t security, uint32_t filter, uint8_t cpulist)
{
    (void)security;
    gic_send_sgi(id, filter, cpulist);
}

uint32_t interrupt_acknowledge(void)
{
    return gic_get_active_irq();
}

void interrupt_irq_enable(uint32_t irqn)
{
    gic_enable_irq(irqn);
}

void interrupt_irq_disable(uint32_t irqn)
{
    gic_disable_irq(irqn);
}

void interrupt_irq_finish(uint32_t irqn)
{
    gic_set_eoi(irqn);
}

void interrupt_irq_prio(uint64_t irqn, uint8_t prio)
{
    gic_set_priority(irqn, prio);
}

void interrupt_irq_icfgr(uint64_t irqn, uint8_t cfg)
{
    gic_set_cfg(irqn, cfg);
}

void interrupt_irq_set_pend(uint64_t irqn)
{
    gic_set_pend(irqn);
}

void interrupt_irq_clear_pend(uint64_t irqn)
{
    gic_clear_pend(irqn);
}

void interrupt_irq_set_act(uint64_t irqn)
{
    gic_set_active(irqn);
}

void interrupt_irq_clear_act(uint64_t irqn)
{
    gic_clear_active(irqn);
}

void interrupt_irq_trgt(uint64_t irqn, uint32_t target)
{
    gic_set_targets(irqn, target);
}

uint64_t interrupt_irq_get_typer(void)
{
    return gic_read_typer();
}

